/* 
 * Copyright 2010 Ziya Guven Koylu, Ozge Koylu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.koylu.caffein.exception;

import com.koylu.caffein.model.clazz.Node;

public class ClazzConfigException extends Exception{

	private Node node;
	
	public ClazzConfigException(String message) {
		super(message);
	}
	
	public ClazzConfigException(String message, Throwable cause) {
		super(message, cause);
	}
	
	public ClazzConfigException(String message, Node node) {
		super(message + " NodePath[" + getNodePath(node)+"]");
		this.node = node;
	}
	
	public ClazzConfigException(String message, Throwable cause, Node node) {
		super(message + " NodePath[" + getNodePath(node)+"]", cause);
		this.node = node;
	}
	
	public Node getNode() {
		return node;
	}
	
	private static String getNodePath(Node node){
		String path = node.toString();
		Node parent = node.getParent();
		while(parent.getParent() != null){
			path = parent.toString() +" > "+ path;
			parent = parent.getParent();
		}
		return parent.toString() +" > "+ path;
	}
}